$NG.AllReady(function (page, { useAction, useValuesChange, useUpdateRow, useDataIndexChange, useUpdateRows, useClick }) {
    var mstform = $NG.getCmpApi("p_form_detailed_design"); //获取表头数据
    var dgrid = $NG.getCmpApi("p_form_detailed_design_d"); //获取表体数据
    var toolbar = $NG.getCmpApi("toolbar_top");
    var toolbar_dgrid = $NG.getCmpApi("toolbar_p_form_detailed_design_d");
    const profit = $NG.getCmpApi("p_form_detailed_design_d");
    const headerTable = $NG.getCmpApi("p_form_detailed_design");
    const gridToolbar = $NG.getCmpApi("toolbar_p_form_detailed_design_d");
    // gridToolbar.getItem('imp').setProps({children:'引用设备清单明细'})
  
    //////////////////////////////////////////////////--init--//////////////////////////////////////////////////
  
    const toolbars = [
      { toolbar: toolbar, items: ["imp"] },
      { toolbar: toolbar_dgrid, items: ["addrow", "attachment", "imp", "imp_push"] },
    ];
  
    // 批量隐藏按钮
    toolbars.forEach(({ toolbar, items }) => {
      if (toolbar) {
        items
          .map((item) => toolbar.getItem(item)) // 提前获取所有按钮
          .filter(Boolean) // 过滤掉不存在的按钮
          .forEach((toolbarItem) => toolbarItem.setHidden()); // 隐藏按钮
      }
    });
  
    toolbar_dgrid.insert({
      id: "addeq",
      text: "引用设备清单",
      iconCls: "icon-New",
    });
  
    if (page.oType == "add" || page.oType == "edit" || page.oType == "copy") {
      fieldSetHidden();
      filterCntMain();
      if (mstform.getItem("phid_pc").getValue()) {
        getProject();
      }
    }
  
    $NG.updateUI((updater)=>{
        updater.editGrid.p_form_detailed_design_d.Cell42.u_detailed_qty.setProps({
                hidden:true
        })
    })
    //////////////////////////////////////////////////--toobar--//////////////////////////////////////////////////
    useClick(async function ({ args }) {
      addEqClick();
    }, "addeq");
  
    //////////////////////////////////////////////////--mstform--//////////////////////////////////////////////////
  
    useValuesChange(({ args }) => {
      cleanCntInfo();
      filterCntMain();
      getProject();
    }, "p_form_detailed_design.phid_pc");
    useValuesChange(({ args }) => {
      getCntInfo();
    }, "p_form_detailed_design.u_cnt_name");
    //监听深化设计类型
    useValuesChange(({ args }) => {
      fieldSetHidden();
    }, "p_form_detailed_design.u_detailed_type");
    // 监听是否影响工期
    useValuesChange(({ args }) => {
      // console.log(`工期监听`, args);
      const _value = headerTable.getItem("u_is_impact_schedule").getValue();
      // console.log(`是否影响工期`, _value);
      let lock = false;
      if (Number(_value) == 1) {
        lock = true;
      } else {
        lock = false;
      }
      $NG.updateUI(function (updater, state) {
        updater.fieldSetForm.p_form_detailed_design.u_is_adjust_schedule.setProps({
          required: lock, //required是否必输
        });
      });
    }, "p_form_detailed_design.u_is_impact_schedule");
  
    //////////////////////////////////////////////////--dgrid--//////////////////////////////////////////////////
  
    useUpdateRow(({ args }) => {
      let record = args[0];
      checkData(record);
      dgrid.refreshView();
    }, "p_form_detailed_design_d");
  
    useUpdateRows(async ({ args }) => {
      // 使用 map 来处理所有的行
      const rowPromises = args[0].map(async (row) => {
        await getEqDInfoByphid(row);
        updateCosts([row]);
      });
      // 等待所有的行处理完成
      await Promise.all(rowPromises);
      // 所有行处理完成后刷新视图
      caculatedgrid();
      await dgrid.refreshView();
    }, "p_form_detailed_design_d");
  
    {
      //表体订阅字段更新逻辑BEGIN
      // 统一的更新逻辑函数
      function updateCosts(args) {
        console.log("updateCosts begin");
        args[0].u_sub_cost_detailed_this = (args[0].u_detailed_qty_this || 0) * (args[0].u_sub_prc || 0);
        args[0].u_sub_cost_detailed = (args[0].u_detailed_qty || 0) * (args[0].u_sub_prc || 0);
  
        args[0].u_pur_cost_detailed_this = (args[0].u_detailed_qty_this || 0) * (args[0].u_pur_prc || 0);
        args[0].u_pur_cost_detailed = (args[0].u_detailed_qty || 0) * (args[0].u_pur_prc || 0);
  
        args[0].u_self_cost_detailed_this = (args[0].u_detailed_qty_this || 0) * (args[0].u_self_prc || 0);
        args[0].u_self_cost_detailed = (args[0].u_detailed_qty || 0) * (args[0].u_self_prc || 0);
        dgrid.refreshView();
      }
  
      // 用于绑定触发字段和更新的通用函数
      const createChangeHandler = (fields) => {
        fields.forEach((field) => {
          useDataIndexChange(({ args, instance }) => {
            updateCosts(args);
            instance.updateRow(args[0]);
            caculatedgrid();
          }, field);
        });
      };
      // 绑定字段变化以触发更新
      createChangeHandler(["p_form_detailed_design_d.u_detailed_qty_this", "p_form_detailed_design_d.u_detailed_qty"]);
  
      useDataIndexChange(({ args, instance }) => {}, "u_detailed_qty");
      useDataIndexChange(({ args, instance }) => {}, "u_detailed_qty_this");
    } //表体订阅字段更新逻辑END
  
    // 方法定义
  
    ////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////
  
    function getEqDInfoByphid(items) {
      console.log("触发方法: getEqDInfoByphid");
  
      return new Promise((resolve) => {
        if (items.u_equipment_item && !items.u_equipment_list_no) {
          $NG.execServer("getEqDInfoByphid", { phid: items.u_equipment_item }, (res) => {
            if (res.count > 0) {
              const data = JSON.parse(res.data)[0].extendObjects;
              console.log("getEqDInfoByphid", data);
              items.u_revenue_type = data.u_revenue_type; // 收入类型
              items.u_revenue_type_EXName = data.u_revenue_type_name;
              items.u_pc_subitem_category = data.u_pc_subitem_category;
              items.u_equipment_list_no = data.u_equipment_list_no; // 设备清单编码
              items.u_cnt_d_no = data.u_cnt_item_no; // 合同清单编码
              items.u_cnt_d = data.u_cnt_item; // 合同清单名称
              items.u_cnt_d_EXName = data.u_cnt_item_name; // 合同清单名称
              items.u_unit = data.u_msunit;
              items.u_unit_EXName = data.u_msunit_name; // 计量单位名称
              items.u_cnt_d_spec = data.u_spec; // 规格型号
              items.u_desc = data.u_tech_params; // 技术参数
              items.u_brand_name = data.u_brand_name; // 品牌
              items.u_cnt_d_taxrate = data.u_cnt_item_tax_rate; // 税率
              items.u_cnt_qty = data.u_qty; // 合同清单数量
              items.u_cnd_d_prc = data.u_cnt_prc; // 未税单价
              items.u_cnt_d_amt = data.u_cnt_amt; // 未税金额
              items.u_sub_item = data.u_sub_item;
              items.u_sub_item_EXName = data.u_sub_item_name;
              items.u_sub_item_name = data.u_sub_item_name;
              items.u_sub_item_spec = data.u_sub_ggxh;
              items.u_sub_item_msunit = data.u_sub_item_msunit;
              items.u_sub_item_msunit_EXName = data.u_subunit_name;
              items.u_sub_prc = data.u_sub_prc;
              items.u_sub_cost = data.u_sub_cost;
              items.u_pur_item = data.u_pur_item;
              items.u_pur_item_EXName = data.u_pur_item_name;
              items.u_pur_item_name = data.u_pur_item_name;
              items.u_pur_item_spec = data.u_pur_ggxh;
              items.u_pur_item_msunit = data.u_pur_item_msunit;
              items.u_pur_item_msunit_EXName = data.u_purunit_name;
              items.u_pur_prc = data.u_pur_prc;
              items.u_pur_cost = data.u_pur_cost;
              items.u_self_item = data.u_self_item;
              items.u_self_item_EXName = data.u_self_item_name;
              items.u_self_item_name = data.u_self_name;
              items.u_self_item_spec = data.u_self_ggxh;
              items.u_self_item_msunit = data.u_self_item_msunit;
              items.u_self_item_msunit_EXName = data.u_purunit_name;
              items.u_self_prc = data.u_self_prc;
              items.u_self_cost = data.u_self_cost;
            } else {
              console.log("功能扩展为空: getEqDInfoByphid");
            }
            resolve(); // **确保 `Promise` 结束**
          });
        } else {
          resolve(); // **确保 `Promise` 结束**
        }
      });
    }
  
    function addEqClick() {
      if (!mstform.getItem("phid_pc").getValue()) {
        $NG.alert("请先选择项目");
        return;
      }
  
      let sqlFilter = `m.phid_pc = ${mstform.getValues().phid_pc}  and gzdy.u_point_qty>=0 and (shsj.u_detailed_qty_this is null or shsj.u_detailed_qty_this<gzdy.u_point_qty) `;
  
      $NG.external
        .openNGHelp({
          type: "NGMultipleHelp",
          helpId: "sbqd",
          valueField: "phid",
          labelField: "d.u_equipment_list_name",
          clientSqlFilter: sqlFilter,
        })
        .then((data) => {
          if (Array.isArray(data) && data.length > 0) {
            console.log(data);
            var gridArr = [];
            var gridCount = data.length;
            console.log(gridCount);
            for (var i = 0; i < gridCount; i++) {
              var gridObj = {};
              gridObj.u_equipment_item = data[i].origin.phid;
              gridObj.u_equipment_item_EXName = data[i].origin.u_equipment_list_no || "";
              gridObj.u_work_unit_qty = data[i].origin.u_point_qty || 0;
              gridObj.u_detailed_qty = data[i].origin.u_detailed_qty_this || 0;
              gridObj.u_u_total_shsj = data[i].origin.u_detailed_qty_this || 0;
              gridObj.u_detailed_qty_this = (data[i].origin.u_point_qty || 0) - (data[i].origin.u_detailed_qty_this || 0);
              gridArr.push(gridObj);
            }
            console.log(gridArr);
            dgrid.addRows(gridArr);
            dgrid.refreshView();
          }
        });
    }
  
    //根据项目筛选合同
    function filterCntMain() {
      $NG.updateUI((updater, state) => {
        console.log("过滤参数检查", updater);
        updater.fieldSetForm.p_form_detailed_design.u_cnt_name.setProps({
          onBeforeOpen: async () => {
            var phid_pc = mstform.getItem("phid_pc").getValue();
            if (!phid_pc) {
              $NG.alert("请先选择项目");
              return false;
            } else {
              return true;
            }
          },
          ...(!!mstform.getItem("phid_pc").getValue() && {
            clientSqlFilter: {
              bill_type: 1, //合同类型
              phid_pc: mstform.getItem("phid_pc").getValue(),
            },
          }),
        });
      });
    }
    // 获取项目信息
    function getProject() {
      if (!mstform.getItem("phid_pc").getValue()) return;
      $NG.execServer("getPtInfoByPhid", { phid: mstform.getItem("phid_pc").getValue() }, function (res) {
        try {
          const datas = JSON.parse(res.data)[0].extendObjects;
          console.log(`获取功能扩展信息:getPtInfoByPhid`, datas);
          $NG.updateState((updater) => {
            updater.data.p_form_detailed_design.setProps({
              u_equipment_list_total_cost: datas.u_total_cost_amt,
              // , u_equipment_list_sub_cost: datas.u_sub_cost_amt
              // , u_equipment_list_pur_cost: datas.u_pur_cost_amt
              // , u_equipment_list_self_cost: datas.u_self_cost
              u_equipment_list_impl_amt: datas.u_implement_amt,
              u_equipment_list_svc_amt: datas.u_svc_cost_amt,
              u_pc_no: datas.pc_no,
              u_sqgw: {
                //售前顾问
                value: datas.user_sqgw_phid,
                label: datas.user_sqgw_name,
              },
              u_project_manager: {
                //项目经理
                value: datas.project_manager_phid,
                label: datas.project_manager_name,
              },
              u_customer_manager: {
                //客户经理
                value: datas.project_manager_phid,
                label: datas.project_manager_name,
              },
            });
          });
        } catch (err) {
          console.log("解析数据出错:getPtInfoByPhid");
        }
      });
      getCntCount("p_form_detailed_design", "u_cnt_name", () => {
        getCntInfo();
      });
      window.deep_design_sum = [];
      $NG.execServer("getDeepDesignQtyByPhidPc", { phid_pc: mstform.getValues().phid_pc, m_phid: mstform.getValues().phid || 0 }, (res) => {
        console.log(`获取数据:getDeepDesignQtyByPhidPc`, res);
        try {
          const _data = JSON.parse(res.data);
          if (!Array.isArray(_data) || _data.length === 0) return;
          window.deep_design_sum = _data.map((item) => item.extendObjects);
          console.log("window.deep_design_sum", window.deep_design_sum);
        } catch (err) {
          console.log("解析数据出错:getDeepDesignQtyByPhidPc");
        }
      });
    }
  
    function checkData(record) {
      // 如果没有找到符合条件的工作单元，再进行清单数量的校验
      if (Number(record.u_detailed_qty_this) + Number(record.u_detailed_qty) > record.u_work_unit_qty) {
        $NG.alert(`设备清单 ${record.u_equipment_list_no} 的深化数量 ${Number(record.u_detailed_qty_this) + Number(record.u_detailed_qty)} 超出工作单元数量 ${record.u_work_unit_qty}`);
        record.u_detailed_qty_this = null;
        record.u_pur_cost_detailed_this = null;
        record.u_sub_cost_detailed_this = null;
        record.u_self_cost_detailed_this = null;
        return; // 终止后续计算，避免不必要的操作
      }
    }
  
    //合同信息获取
    async function getCntInfo() {
      if (!mstform.getItem("u_cnt_name").getValue()) return;
      console.log(`合同信息获取:getCntInfo`);
      $NG.execServer("getCntMInfoByPhid", { phid: mstform.getItem("u_cnt_name").getValue() }, function (res) {
        const datas = JSON.parse(res.data)[0].extendObjects;
        $NG.updateState((updater) => {
          updater.data.p_form_detailed_design.setProps({
            u_cnt_no: datas.pcm_no, //合同编码
            u_cnt_revenue: datas.cnt_sum_vat_fc, //合同收入
            u_customer: {
              // 客户名称
              value: datas.customer_id,
              label: datas.customer_name,
            },
          });
        });
      });
    }
    //合同信息清空
    function cleanCntInfo(params) {
      $NG.updateState((updater) => {
        updater.data.p_form_detailed_design.setProps({
          u_cnt_no: "", //合同编码
          u_cnt_name: "", //合同选择
          u_cnt_revenue: "", //合同收入
          u_customer: {
            // 客户名称
            value: "",
            label: "",
          },
        });
      });
    }
    // 设置字段是否隐藏
    function fieldSetHidden(params) {
      console.log("深化设计类型监听", mstform.getItem("u_detailed_type").getValue());
      let lock = false;
      if (Number(mstform.getItem("u_detailed_type").getValue()) == 1) {
        lock = true;
      } else {
        lock = false;
      }
      //表体多字段设置属性
      $NG.updateUI((updater) => {
        const fields = ["u_detailed_gp", "u_detailed_gm", "u_revenue_diff", "u_gp_diff"];
        fields.forEach((field) => {
          updater.fieldSetForm.p_form_detailed_design[field].setProps({
            hidden: lock, //隐藏
            // required: true, //必输
            // disabled: true, //只读
          });
        });
      });
    }
    //汇总表体数据到表头
    function caculatedgrid() {
      console.log("caculatedgrid begin");
      let sub_cost_detailed_this = 0;
      let sub_cost_detailed = 0;
  
      let pur_cost_detailed_this = 0;
      let pur_cost_detailed = 0;
  
      let self_cost_detailed_this = 0;
      let self_cost_detailed = 0;
  
      let cost_detailed_this = 0;
      let cost_detailed = 0;
      const Rows1 = $NG.getCmpApi("p_form_detailed_design_d").getRows();
      Rows1.forEach((items) => {
        sub_cost_detailed_this += Number(items.u_sub_cost_detailed_this) || 0;
        sub_cost_detailed += Number(items.u_sub_cost_detailed) || 0;
  
        pur_cost_detailed_this += Number(items.u_pur_cost_detailed_this) || 0;
        pur_cost_detailed += Number(items.u_pur_cost_detailed) || 0;
  
        self_cost_detailed_this += Number(items.u_self_cost_detailed_this) || 0;
        self_cost_detailed += Number(items.u_self_cost_detailed) || 0;
        items.u_u_total_shsj = (Number(items.u_detailed_qty) || 0) + (Number(items.u_detailed_qty_this) || 0)
      });
  
      cost_detailed_this = sub_cost_detailed_this + pur_cost_detailed_this + self_cost_detailed_this;
      cost_detailed = sub_cost_detailed + pur_cost_detailed + self_cost_detailed;
  
      $NG.updateState((updater) => {
        console.log(`sub_cost_detailed_this: ${sub_cost_detailed_this}, sub_cost_detailed: ${sub_cost_detailed}, pur_cost_detailed_this: ${pur_cost_detailed_this}, pur_cost_detailed: ${pur_cost_detailed}, self_cost_detailed_this: ${self_cost_detailed_this}, self_cost_detailed: ${self_cost_detailed}, cost_detailed_this: ${cost_detailed_this}, cost_detailed: ${cost_detailed}`);
        updater.data.p_form_detailed_design.setProps({
          u_detailed_sub_cost: sub_cost_detailed, //
          u_detailed_sub_cost_this: sub_cost_detailed_this, //
  
          u_detailed_pur_cost_this: pur_cost_detailed_this, //
          u_detailed_pur_cost: pur_cost_detailed, //
  
          u_detailed_self_cost_this: self_cost_detailed_this, //
          u_detailed_self_cost: self_cost_detailed, //
  
          u_detailed_total_cost_this: cost_detailed_this,
          // u_detailed_total_cost_this: cost_detailed_this + mstform.getItem('u_equipment_list_impl_amt').getValue() + mstform.getItem('u_equipment_list_svc_amt').getValue(),
          u_detailed_total_cost: cost_detailed,
          // u_detailed_total_cost: cost_detailed + mstform.getItem('u_equipment_list_impl_amt').getValue() + mstform.getItem('u_equipment_list_svc_amt').getValue()
        });
      });
      // console.log('u_total_cost_amt_vat:' + mstform.getItem('u_total_cost_amt_vat').getValue());
    }
  
    //获取合同数量
    function getCntCount(table, key, fun) {
      if (!$NG.getCmpApi(table).getItem("phid_pc").getValue()) return;
      $NG.execServer("getCntCount", { type: 1, phid_pc: $NG.getCmpApi(table).getItem("phid_pc").getValue() }, (res) => {
        console.log(res, "count");
        switch (res.count) {
          case 0:
            return;
          case 1:
            const datas = JSON.parse(res.data)[0].extendObjects;
            const temp_map = {};
            temp_map[key] = datas.phid;
            temp_map[`${key}_EXName`] = datas.bill_name;
            $NG.updateState((updater) => {
              updater.data[table].setProps({
                ...temp_map,
              });
              setTimeout(() => {
                if (fun) {
                  fun();
                }
              }, 200);
            });
        }
      });
    }
  });
  
  // async function getSbqdInfo() {
  //   if (!mstform.getItem("u_cnt_name").getValue()) return;
  //   await $NG.execServer("getSbqdDetailByCnt", { cnt: mstform.getItem("u_cnt_name").getValue() }, (res) => {
  //     if (res.count == 0) {
  //       return;
  //     }
  //     const _data = JSON.parse(res.data);
  //     console.log(`获取设备清单`, _data);
  //     let _arr = [];
  //     _data.forEach((items) => {
  //       const item = items.extendObjects;
  //       _arr.push({ ...item });
  //     });
  //     window._lsz_sbqdDetail = [..._arr];
  //   });
  // }
  // //获取工作单元中设备清单明细
  // async function getGzdyD2Detail() {
  //   await $NG.execServer("getGzdyD2Detail", { u_cnt: mstform.getItem("u_cnt_name").getValue() }, (res) => {
  //     console.log(res);
  //     if (res.count == 0) return;
  //     const _data = JSON.parse(res.data);
  //     console.log(`获取明细`, _data);
  //     const _tempData = [];
  //     _data.forEach((items) => {
  //       const item = items.extendObjects;
  //       // 匹配设备清单明细
  //       let _map = {};
  //       let count_amt_nfb = 0;
  //       let count_amt_ncg = 0;
  //       let count_amt_nzz = 0;
  //       if (window._lsz_sbqdDetail) {
  //         window._lsz_sbqdDetail.forEach((sbItem) => {
  //           console.log(sbItem.phid, item.sbqd_phid);
  //           if (sbItem.phid == item.sbqd_phid) {
  //             console.log("匹配成功的设备清单", sbItem);
  //             _map.u_revenue_type = sbItem.u_revenue_type;
  //             _map.ur_exname = sbItem.ur_exname;
  //             _map.phid = sbItem.phid;
  //             _map.u_equipment_list_name = sbItem.u_equipment_list_name;
  //             _map.u_pc_subitem_category = sbItem.u_pc_subitem_category;
  //             _map.u_cnt_item_no = sbItem.u_cnt_item_no;
  //             _map.u_cnt_item = sbItem.u_cnt_item;
  //             _map.u_cnt_item_exname = sbItem.u_cnt_item_exname;
  //             _map.u_cnt_item_exname = sbItem.u_cnt_item_exname;
  //             _map.u_tech_params = sbItem.u_tech_params;
  //             _map.u_msunit = sbItem.u_msunit;
  //             _map.u_msunit_exname = sbItem.u_msunit_exname;
  //             _map.u_brand = sbItem.u_brand;
  //             _map.u_brand_exname = sbItem.u_brand_exname;
  //             _map.u_qty = sbItem.u_qty;
  //             _map.u_cnt_prc = sbItem.u_cnt_prc;
  //             _map.u_cnt_amt = sbItem.u_cnt_amt;
  //             _map.u_sub_item = sbItem.u_sub_item;
  //             _map.u_sub_name = sbItem.u_sub_name;
  //             _map.u_sub_item_exname = sbItem.u_sub_item_exname;
  //             _map.u_sub_name = sbItem.u_sub_name;
  //             _map.u_sub_ggxh = sbItem.u_sub_ggxh;
  //             _map.u_sub_item_msunit = sbItem.u_sub_item_msunit;
  //             _map.u_sub_item_msunit_exname = sbItem.u_sub_item_msunit_exname;
  //             _map.u_sub_prc = sbItem.u_sub_prc;
  //             _map.u_sub_cost = sbItem.u_sub_cost;
  //             _map.u_pur_item = sbItem.u_pur_item;
  //             _map.u_pur_item_exname = sbItem.u_pur_item_exname;
  //             _map.u_pur_name = sbItem.u_pur_name;
  //             _map.u_pur_ggxh = sbItem.u_pur_ggxh;
  //             _map.u_pur_item_msunit = sbItem.u_pur_item_msunit;
  //             _map.u_pur_item_msunit_exname = sbItem.u_pur_item_msunit_exname;
  //             _map.u_pur_prc = sbItem.u_pur_prc;
  //             _map.u_pur_cost = sbItem.u_pur_cost;
  //             _map.u_self_item = sbItem.u_self_item;
  //             _map.u_self_item_exname = sbItem.u_self_item_exname;
  //             _map.u_self_name = sbItem.u_self_name;
  //             _map.u_self_ggxh = sbItem.u_self_ggxh;
  //             _map.u_self_item_msunit = sbItem.u_self_item_msunit;
  //             _map.u_self_item_msunit_exname = sbItem.u_self_item_msunit_exname;
  //             _map.u_self_prc = sbItem.u_self_prc;
  //             _map.u_self_cost = sbItem.u_self_cost;
  //             for (let key in item) {
  //               _map[key] = item[key];
  //             }
  //             _tempData.push({ ..._map });
  //           }
  //         });
  //         // $NG.updateState((updater)=>{
  //         //     updater.data.p_form_detailed_design.setProps({
  //         //         u_equipment_list_sub_cost:count_amt_nfb,
  //         //         u_equipment_list_pur_cost:count_amt_ncg,
  //         //         u_equipment_list_self_cost:count_amt_nzz,
  //         //     })
  //         // })
  //       }
  //     });
  //     console.log(`预备数据`, _tempData);
  //     window._catch_sbqd = [..._tempData];
  //   });
  // }
  
  // // 获取最新的深化设计
  // async function getNEWshsj() {
  //   await $NG.execServer("getNEWshsj", { u_cnt: mstform.getItem("u_cnt_name").getValue() }, (res) => {
  //     // console.log(res);
  //     if (res.count == 0) return;
  //     window._lsz_newLock = true; // 标识已有
  //     const _data = JSON.parse(res.data);
  //     // console.log(`获取最新`, _data);
  //     const newData = [];
  //     //提取最新的一条
  //     const _newRow = _data[0].extendObjects.phid;
  //     _data.forEach((item) => {
  //       if (item.extendObjects.phid == _newRow) {
  //         newData.push({ ...item.extendObjects });
  //       }
  //     });
  //     //缓存最新的深化设计清单
  //     window._lsz_newShsj = [...newData];
  //   });
  // }
  
  // function sumShReduce() {
  //   const _arr = dgrid.getRows();
  //   _arr.forEach((item) => {
  //     item.u_sub_cost_detailed_this = (Number(item.u_detailed_qty_this) || 0) * (Number(item.u_sub_prc) || 0);
  //     item.u_pur_cost_detailed_this = (Number(item.u_pur_prc) || 0) * (Number(item.u_detailed_qty_this) || 0);
  //     item.u_self_cost_detailed_this = (Number(item.u_self_prc) || 0) * (Number(item.u_detailed_qty_this) || 0);
  //   });
  //   dgrid.refreshView();
  // }
  